library lib_message_center;

import 'package:flutter/services.dart';
import 'package:rxdart/subjects.dart';

class LibMessageCenter {
  static final LibMessageCenter instance = LibMessageCenter._internal();

  final MethodChannel _channel = const MethodChannel('lib-message-center');

  final BehaviorSubject<int> unreadCount = BehaviorSubject<int>.seeded(0);

  LibMessageCenter._internal() {
    _channel.invokeMethod("getUnreadCount").then((value) {
      unreadCount.add(value);
    });

    _channel.setMethodCallHandler((call) async {
      if (call.method == 'onUnreadCountChanged') {
        unreadCount.add(call.arguments);
      }
    });
  }

  void resetUnreadCount() {
    _channel.invokeMethod("resetUnreadCount");
  }
}
